﻿Imports System.Data
Imports ADOEntity

Partial Class KYC_IndividualCDDPopup
    Inherits System.Web.UI.Page

    Dim clsDatabase As New clsDatabase
    Dim userEdmx As ADOEntity.UserEntities
    Dim key As String = "Encrytion By Fusionsoft Solution"

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btnConfirm_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnConfirm.Click
        Dim txtUserName As String = txtApproveNo.Text
        Dim txtPassword As String = txtApprovePassword.Text

        Dim clsMenuRight As New clsSessionMenuRight
        Dim clsDataTable As New clsLINQToDataTable
        Dim clsDateFormat As New clsDateFormat
        userEdmx = New UserEntities

        Dim userQuery = (From userQ In userEdmx.SUSER Group Join tblBranch In userEdmx.SBRANCH _
                                                            On userQ.BRANCHCODE Equals tblBranch.BRANCHCODE Into leftJoin = Group
                                From tblLeftBranch In leftJoin.DefaultIfEmpty
                         Where userQ.USERNAME = txtUserName _
                         Select userQ.USERRIGHT, userQ.USERNAME, userQ.PASSWORD, userQ.BRANCHCODE, _
                                 tblLeftBranch.BRANCHNAME, userQ.PWDBEGINDATE, userQ.ZONECODE, userQ.ALLCODERIGHT, _
                                 userQ.PWDEXPIREDATE, userQ.ISPWDEXPIRE, userQ.MUSTCHANGEPWD, userQ.CURRENTLOCKNUM, _
                                 userQ.USEREXPIREDATE, userQ.ISUSEREXPIRE, _
                                 userQ.ISPWDLOCK, userQ.ISINACTIVE, userQ.DEPTCODE, userQ.ROLECODE, userQ.ISLOGIN).ToList

        If Not (userQuery.Count = 0) Then

            If (checkPasswordLogin(userQuery(0).PASSWORD, txtPassword)) Then
                ScriptManager.RegisterStartupScript(Me, _
                                                           Me.GetType(), _
                                                           "clientScript", _
                                                           " window.opener.form1.txtApprove.value = 'Y'; window.opener.form1.txtAuthorizeOwner.value = '" + txtApproveNo.Text + "'; window.opener.form1.txtApproveDate.value = '" + txtDApproveDate.Text + "'; closeWindowComplete();", _
                                                           True)
            Else
                ScriptManager.RegisterStartupScript(Me, _
                                                           Me.GetType(), _
                                                           "clientScript", _
                                                           " window.opener.form1.txtApprove.value = 'N'; closedWindowFail();", _
                                                           True)
            End If

        Else
            ScriptManager.RegisterStartupScript(Me, _
                                                       Me.GetType(), _
                                                       "clientScript", _
                                                       " window.opener.form1.txtApprove.value = 'N'; closedWindowFail();", _
                                                       True)

        End If




        

    End Sub


    Public Function checkPasswordLogin(ByVal strPassDB As String, ByVal strPwdLogin As String) As Boolean
        Dim chkPass As Boolean = False
        Dim clschkPassword As New Crypto

        Dim alg As Crypto.Algorithm = Crypto.Algorithm.Rijndael
        Crypto.EncryptionAlgorithm = alg
        Crypto.Key = key
        Crypto.Encoding = Crypto.EncodingType.BASE_64
        Crypto.Content = strPassDB
        chkPass = Crypto.DecryptString()
        If (Crypto.Content = strPwdLogin) Then
            chkPass = True
        Else
            chkPass = False
        End If
        clschkPassword = Nothing

        Return chkPass
    End Function

End Class
